/*
  important:
  to realloc matrix two dimension dynamically.
 */
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "BFS.h"

enum Color
{
	BLACK,
	WHITE,
	GRAY
};

typedef struct graph
{
	int number;
	Color color;
	int value;
	struct graph *next;
}graph;

graph* xalloc()
{
	graph* p = (graph*)malloc(sizeof(graph));

	if(p == NULL) 
	{
//		syslog("memory alloc fail!!!");
		exit(1);
	}
	return p;
}

int main_bfs() 
{ 

#ifdef FILEIO
  freopen("in-bfs.txt","r",stdin); 
  freopen("out-bfs.txt","w",stdout); 
#endif
  int N;                        // number of matrix
  int i,j;                      // for loop
  int **m;  
  graph* array;// matrix to store

  scanf("%d",&N);

//  array = MakeAdjacentLink(N);
  // TODO: convert the matrix to the adjacency link list



#ifdef FILEIO
  fclose(stdin);
  fclose(stdout);
#endif  
  
  return 0; 
}


graph* MakeAdjacentLink(int N)
{
  int i,j;
  graph *array;
  int **a;
  graph *p,*np;
  int vertex=N;

  a = (int **)malloc(sizeof(int *)*N);
  memset(a,0,sizeof(int *)*N);
  array = (graph *)malloc(sizeof(graph)*N);
  memset(array,0,sizeof(graph)*N);

  for(i = 0;i<N;i++)
    {
      a[i] = (int *)malloc(N*sizeof(int));
      memset(a[i],0,sizeof(int)*N);
      
      for(j = 0;j<N;j++)
        {
          scanf("%d",&a[i][j]);
        }
    }

  for(i = 0;i<vertex;i++)
    {
      array[i].number = i + 1;
      array[i].color = WHITE;
      array[i].value = 0;
      array[i].next = NULL;
    }

  /*
   * if a[[i][j] != 0 , alloc a node link it into the parent node
   */
  for(i = 0;i<vertex;i++)
    {
      p = &array[i];
      for(j = 0;j<vertex;j++)
        {
          if(a[i][j] != 0)
            {
              np = xalloc();
              np -> number = j + 1;
              np -> color = WHITE;
              np -> value = 0;
              np -> next = NULL;
              p -> next = np;
              p = np;
            }
        }
    }

 return array;
}
